home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / amipop17.zip / POP_MAIN.C < prev    next >
C/C++ Source or Header  |  1993-11-15  |  7KB  |  391 lines

  1. /* AmiPOP By Scott Ellis */
  2.  
  3. #include "pop.h"
  4.  
  5. static const char VersionID[]="\0$VER:AmiPOP 1.7á(15.11.93) By Scott Ellis";
  6.  
  7. /* Variables in pop.h */
  8.  
  9. char *pophost=NULL;
  10. char *username=NULL;
  11. char *password=NULL;
  12. char *passfake=NULL;
  13. char *maildir=NULL;
  14. char *cxname=NULL;
  15. char *cxdesc=NULL;
  16. char *hotkey=NULL;
  17. char *title=NULL;
  18. char *temp=NULL;
  19. char *buf=NULL;
  20. UBYTE *PubScreenName=NULL;
  21.  
  22. char bum[]="Ok";
  23.  
  24. BOOL delmail=FALSE;
  25. BOOL checkper=FALSE;
  26. BOOL appfile=TRUE;
  27. BOOL winop=TRUE;
  28. BOOL notify=FALSE;
  29.  
  30. int timecheck=10;
  31. int port=110;
  32.  
  33. struct MsgPort *amipop_mp=NULL;
  34. struct MsgPort *timer_mp=NULL;
  35. struct timerequest *timerio=NULL;
  36. CxObj *broker=NULL;
  37. struct Library *TimerBase=NULL;
  38.  
  39. struct NewBroker newbroker = {
  40.     NB_VERSION,   /* nb_Version - Version of the NewBroker structure */
  41.     "Not Active", /* nb_Name */
  42.     "Amiga POP ⌐ 1993 Scott Ellis",     /* nb_Title - Title of commodity that appears in CXExchange */
  43.     "Not Active", /* nb_Descr */
  44.     NBU_UNIQUE | NBU_NOTIFY ,            /* nb_Unique - Tells CX not to launch another commodity with same name */
  45.     COF_SHOW_HIDE,            /* nb_Flags - Tells CX if this commodity has a window */
  46.     0,            /* nb_Pri - This commodity's priority */
  47.     0,            /* nb_Port - MsgPort CX talks to */
  48.     0             /* nb_ReservedChannel - reserved for later use */
  49. };
  50.  
  51. struct EasyStruct ereq =
  52.     {
  53.     sizeof(struct EasyStruct),
  54.     0,
  55.     "AmiPOP Notice",
  56.     "%s",
  57.     "%s",
  58.     };
  59.  
  60. UWORD __chip waitPointer[] =
  61.     {
  62.     0x0000, 0x0000,     /* reserved, must be NULL */
  63.  
  64.     0x0400, 0x07C0,
  65.     0x0000, 0x07C0,
  66.     0x0100, 0x0380,
  67.     0x0000, 0x07E0,
  68.     0x07C0, 0x1FF8,
  69.     0x1FF0, 0x3FEC,
  70.     0x3FF8, 0x7FDE,
  71.     0x3FF8, 0x7FBE,
  72.     0x7FFC, 0xFF7F,
  73.     0x7EFC, 0xFFFF,
  74.     0x7FFC, 0xFFFF,
  75.     0x3FF8, 0x7FFE,
  76.     0x3FF8, 0x7FFE,
  77.     0x1FF0, 0x3FFC,
  78.     0x07C0, 0x1FF8,
  79.     0x0000, 0x07E0,
  80.  
  81.     0x0000, 0x0000,     /* reserved, must be NULL */
  82.     };
  83.  
  84. enum args
  85.     {
  86.     USERNAME,
  87.     PASSWORD,
  88.     POPHOST,
  89.     MAILDIR,
  90.     CHECKPER,
  91.     TIME,
  92.     DELETE,
  93.     APPEND,
  94.     NOWINDOW,
  95.     PORT,
  96.     NOTIFY,
  97.     CX_POPKEY,
  98.     PUBSCREEN
  99.     };
  100.  
  101. /* Configure SAS Specific routines */
  102.  
  103. void __regargs __chkabort(void) {}
  104. int __oslibversion=37;
  105. long __stack = 20000;
  106.  
  107. /* End SAS */
  108.  
  109. ULONG            sigmask=NULL;
  110. ULONG            cxsigflag=NULL;
  111. ULONG            timesigflag=NULL;
  112.  
  113. struct Library *IconBase;
  114.  
  115. int main(int argc, char **argv )
  116. {
  117.     int foo=0;
  118.     ULONG    mysig;
  119.  
  120.     if (makevars())
  121.     {
  122.         freevars();
  123.         return(20);
  124.     }
  125.  
  126.     if ( parse( argc, argv) )
  127.     {
  128.         if ( setuptime() )
  129.         {
  130.             timesigflag = 1L << timer_mp->mp_SigBit;
  131.             timereq();
  132.             foo=1;
  133.  
  134.             if ( setupcx() )
  135.             {
  136.                 if (winop)
  137.                 {
  138.                     openup();
  139.                 }
  140.             }
  141.             else
  142.             {
  143.                 foo=0;
  144.             }
  145.         }
  146.     }
  147.     else
  148.     {
  149.         foo=0;
  150.     }
  151.  
  152.         while (foo)
  153.     {
  154.                 if (winop)
  155.         {
  156.             sigmask= 1 << Project0Wnd->UserPort->mp_SigBit ;
  157.         }
  158.         else
  159.         {
  160.             sigmask= NULL;
  161.         }
  162.  
  163.         mysig=Wait ( sigmask | cxsigflag | timesigflag | SIGBREAKF_CTRL_C );
  164.  
  165.         if ( mysig & cxsigflag )
  166.         {
  167.             foo=docx();
  168.         }
  169.                if ( mysig & sigmask )
  170.         {
  171.             foo=HandleProject0IDCMP();
  172.         }
  173.         if ( mysig & timesigflag )
  174.         {
  175.             if (checkper)
  176.             {
  177.                 MYGAD_BUTTONClicked();
  178.             }
  179.             timereq();
  180.         }
  181.         if (mysig & SIGBREAKF_CTRL_C )
  182.         {
  183.                     foo=0;
  184.         }
  185.     }
  186.  
  187.         closedown();
  188.  
  189.     closetime();
  190.  
  191.     closecx();
  192.  
  193.     freevars();
  194.  
  195.     return(0);
  196. }
  197.  
  198. void openup(void)
  199. {
  200.     SetupScreen();
  201.     OpenProject0Window();
  202.  
  203.     winop=TRUE;
  204. }
  205.  
  206. void closedown(void)
  207. {
  208.     CloseProject0Window();
  209.     CloseDownScreen();
  210.  
  211.     winop=FALSE;
  212. }
  213.  
  214. int parse(int argc, char *argv[])
  215. {
  216.     struct RDArgs    *RDA;
  217.     LONG         ArgumentArray[14] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
  218.     char        **ToolArrayIndex,
  219.                 *ToolStringIndex,
  220.                 *Template;
  221.     struct DiskObject    *DiskObject;
  222.     char none[]="None Given";
  223.  
  224.     if (IconBase = OpenLibrary("icon.library", 36L ) )
  225.         {
  226.  
  227.         RDA = AllocDosObjectTags(DOS_RDARGS, TAG_DONE);
  228.         RDA->RDA_ExtHelp = NULL;
  229.  
  230.         if (_WBenchMsg)
  231.         {
  232.             CurrentDir(_WBenchMsg->sm_ArgList->wa_Lock);
  233.             if ( DiskObject = GetDiskObject(_WBenchMsg->sm_ArgList->wa_Name) )
  234.             {
  235.                 for (ToolArrayIndex = DiskObject->do_ToolTypes; *ToolArrayIndex; ToolArrayIndex++ )
  236.                 {
  237.                     RDA->RDA_Source.CS_Length += (strlen(*ToolArrayIndex)+1);
  238.                 }
  239.                 RDA->RDA_Source.CS_Buffer = AllocVec(RDA->RDA_Source.CS_Length+1,MEMF_CLEAR);
  240.                 ToolStringIndex = RDA->RDA_Source.CS_Buffer;
  241.                 for (ToolArrayIndex = DiskObject->do_ToolTypes; *ToolArrayIndex; ToolArrayIndex++ )
  242.                 {
  243.                         ToolStringIndex = stpcpy(stpcpy(ToolStringIndex, *ToolArrayIndex)," ");
  244.                 }
  245.                 *(ToolStringIndex-1) = '\n';
  246.                 FreeDiskObject(DiskObject);
  247.             }
  248.  
  249.             Template = "Username/K,Password/K,POPHost/K,MailDir/K,CheckPer/S,Time/K/N,Delete/S,Append/S,NoWindow/S,Port/K/N,Notify/S,Cx_Popkey/K,PubScreen/K,ThrowAway/M";
  250.         }
  251.         else
  252.         {
  253.             Template = "Username/K,Password/K,POPHost/K,MailDir/K,CheckPer/S,Time/K/N,Delete/S,Append/S,NoWindow/S,Port/K/N,Notify/S,Cx_Popkey/K,PubScreen/K";
  254.         }
  255.  
  256.         if (RDA = ReadArgs(Template, ArgumentArray, RDA) )
  257.         {
  258.             if (ArgumentArray[USERNAME])
  259.             {
  260.                 strcpy(username,(char *)ArgumentArray[USERNAME]);
  261.             }
  262.             else
  263.             {
  264.                 strcpy(username,none);
  265.             }
  266.  
  267.             if (ArgumentArray[PASSWORD])
  268.             {
  269.                 strcpy(password,(char *)ArgumentArray[PASSWORD]);
  270.             }
  271.             else
  272.             {
  273.                 strcpy(password,"");
  274.             }
  275.  
  276.             if (ArgumentArray[POPHOST])
  277.             {
  278.                 strcpy(pophost,(char *)ArgumentArray[POPHOST]);
  279.             }
  280.             else
  281.             {
  282.                 strcpy(pophost,none);
  283.             }
  284.  
  285.             if (ArgumentArray[MAILDIR])
  286.             {
  287.                 strcpy(maildir,(char *)ArgumentArray[MAILDIR]);
  288.             }
  289.             else
  290.             {
  291.                 strcpy(maildir,none);
  292.             }
  293.  
  294.             checkper=(BOOL)ArgumentArray[CHECKPER];
  295.  
  296.             if (ArgumentArray[TIME])
  297.             {
  298.                 timecheck=*(int *)ArgumentArray[TIME];
  299.             }
  300.  
  301.             delmail=(BOOL)ArgumentArray[DELETE];
  302.             appfile=(BOOL)ArgumentArray[APPEND];
  303.                         winop=!( (BOOL)ArgumentArray[NOWINDOW] );
  304.  
  305.             if (ArgumentArray[PORT])
  306.             {
  307.                 port = *(int *)ArgumentArray[PORT];
  308.             }
  309.  
  310.             notify=(BOOL)ArgumentArray[NOTIFY];
  311.  
  312.             if (ArgumentArray[CX_POPKEY])
  313.             {
  314.                 strcpy(hotkey,(char *)ArgumentArray[CX_POPKEY]);
  315.             }
  316.  
  317.             if (ArgumentArray[PUBSCREEN])
  318.             {
  319.                 strcpy(PubScreenName,(UBYTE *)ArgumentArray[PUBSCREEN]);
  320.             }
  321.  
  322.             if (RDA->RDA_Source.CS_Buffer)
  323.             {
  324.                 FreeVec(RDA->RDA_Source.CS_Buffer);
  325.             }
  326.  
  327.         }
  328.         else
  329.         {
  330.             if (argc==0)
  331.             {
  332.                 doreq("Arguments Incorrect",bum);
  333.             }
  334.             else
  335.             {
  336.                 PrintFault(IoErr(), NULL);
  337.             }
  338.  
  339.             return(0);
  340.         }
  341.  
  342.         FreeArgs(RDA);
  343.         FreeDosObject(DOS_RDARGS,RDA);
  344.             CloseLibrary(IconBase);
  345.     }
  346.     else
  347.     {
  348.         doreq("Can't open icon.library",bum);
  349.         return(0);
  350.     }
  351.     return(1);
  352. }
  353.  
  354. int doreq(char *mes, char *but)
  355. {
  356.     LONG answer;
  357.  
  358.     answer= EasyRequest(NULL, &ereq, NULL, mes, but);
  359.  
  360.     if (Project0Wnd)
  361.     {
  362.         SetWindowTitles(Project0Wnd,Project0Wdt, (UBYTE *) ~0);
  363.     }
  364.  
  365.     return(answer);
  366. }
  367.  
  368. BOOL makevars(void)
  369. {
  370.     if ( pophost=AllocVec((7*BIGSTRING)+(4*SMALLSTRING)+(2*BUFSIZE)+(256),MEMF_CLEAR) )
  371.     {
  372.         username=pophost+BIGSTRING;
  373.         password=username+SMALLSTRING;
  374.         passfake=password+SMALLSTRING;
  375.         maildir=passfake+SMALLSTRING;
  376.         cxname=maildir+BIGSTRING;
  377.         cxdesc=cxname+BIGSTRING;
  378.         hotkey=cxdesc+(3*BIGSTRING);
  379.         title=hotkey+BIGSTRING;
  380.         temp=title+256;
  381.         buf=temp+BUFSIZE;
  382.         PubScreenName=buf+SMALLSTRING;
  383.         return(FALSE);
  384.     }
  385.     return(TRUE);
  386. }
  387.  
  388. void freevars(void)
  389. {
  390.     if (pophost) FreeVec(pophost);
  391. }